import pageination from '../../components/pageination/pageination.vue'

export default {
	data() {
		return {
			//数据
      total: 0, //总条数
      page: 1, //当前页
      size: 10, //每页显示条数
      search: '', //搜索信息
			modelShow: false,
			demandModelShow: false,
      reviewerExpert: {},
      reviewerExpertList: [], //专家评审列表
      applyExpertList: [], //申请专家列表
      projectReviewList: [],//评审信息列表
			uploadNum: 0,
			FileUpload: [],
			 curId: 0,
			 curIndex:-1,//选中下标
		}
	},
	components: {
		pageination
	},
	created() { //调用方法
		let that = this;
    that.searchTodo();
	},
	mounted() {

  },
	methods: { //写函数方法
		//给选中的列加背景色
		choosed:function(index){
			this.curIndex=index;
		},
		//页码切换执行方法
		pageFn: function(val, pid) {
			this.page = parseInt(val);
			//此处调列表数据接口
      this.searchTodo();
		},
		/**返回子组件用户选择的一页显示条数**/
		obtainChild: function(data) {
			this.row = data;
		},
		touchOffIdInput(n) {
			this.uploadNum = n;
			if(n == 1) {
				$("#handIdFront").click();
			}
		},
		/**文件上传js**/
		idFrontImg: function() {
			this.FileUpload = [];
			var picFile = document.getElementById("handIdFront");
			var files = picFile.files;
			for(var i = 0; i < files.length; i++) {
				var file = files[i];
				var name = file.name;
				this.FileUpload.push({
					file: file,
					name: name
				});
			}
		},
		//项目结题模态框
		projectDetails: function(reviewerExpert) {
      this.validScoreCount = 0;
      this.demandModelShow = true;
      this.reviewerExpert = reviewerExpert;
      this.searchAllApplyExpert(reviewerExpert.projectId,1,reviewerExpert.reviewNum);
		},
		//专家申请模态框
		demand: function(reviewerExpert) {
      this.validScoreCount = 0;
      this.demandModelShow = true;
      this.reviewerExpert = reviewerExpert;
      this.searchAllApplyExpert(reviewerExpert.projectId,0,reviewerExpert.reviewNum);
		},
		//关闭模态框
		closeModel: function() {
			this.demandModelShow = false;
		},
    //预览
    preview: function(url,msg) {
      if (url == null || url == "") {
        if (msg == null || msg == "") {
          msg = "附件";
        }
        layer.msg("暂无" + msg + "！");
      } else {
        window.open(this.urls.baseUrl + url);
      }
    },
    //搜索所有申请专家未审核信息列表
    searchAllApplyExpert: function(projectId,matters,reviewNum) {
      if (projectId == null || matters == null || reviewNum == null) {
        return;
      }
		  let that = this;
      that.projectReviewList = [];
      that.$post(
        that.urls.getCurrentExpertAllProjectReview,
        {"matters": matters,"projectId": projectId,"reviewNum": reviewNum}
      )
      .then(function(res) {
        if(res.success) {
          let projectReviewList = res.data;
          for (var i = 0,len = projectReviewList.length;i < len;i++) {
            projectReviewList[i].score = projectReviewList[i].score == null ? 0 : projectReviewList[i].score;
            projectReviewList[i].auditStatus = projectReviewList[i].auditStatus == null ? 1 : projectReviewList[i].auditStatus;
          }
          that.projectReviewList = projectReviewList;
        }
      })
    },
    //确定评审
    defineReviewer: function() {
      let that = this;
      let projectReviewList = that.projectReviewList;
      if (projectReviewList[0].type == 0) {
        for (var i = 0,len = projectReviewList.length;i < len;i++) {
          if (projectReviewList[i].score == null || projectReviewList[i].score == "" || projectReviewList[i].score < 0 || projectReviewList[i].score > 100) {
            layer.msg("请输入0-100的数字！", {
              time: 3000, //3s后自动关闭
            });
            return;
          }
        }
      }
      that.$post(
        that.urls.batchReviewProjectApplication,
        that.projectReviewList
      )
        .then(function(res) {
          let msg = "";
          if(res.success) {
            msg = "评审成功！";
            //重新加载数据
            that.searchTodo();
            //关闭对话框
            that.closeModel();
          } else {
            msg = "评审失败！";
          }
          layer.msg(msg, {
            time: 3000, //3s后自动关闭
          });
        })
    },
    //搜索数据列表
    searchTodo: function() {
      let that = this;
      that.$post(
        that.urls.getCurrentExpertProjectReviewPageInfo, {
          "pageNum": that.page,
          "pageSize": that.size,
          "search": that.search
        }
      )
      .then(function(res) {
        if(res.success) {
          that.reviewerExpertList = res.pageInfo.list;
          that.total = res.pageInfo.total;
          that.page = res.pageInfo.pageNum;
        }
      })
    },
	}
}
